package com.orm.mybatis.serviceImpl;

import com.orm.mybatis.entity.Permission;
import com.orm.mybatis.mapper.PermissionMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * (Permissions)表服务实现类
 *
 * @author makejava
 * @since 2022-03-05 12:00:41
 */
@Service
public class PermissionsServiceImpl {

    @Resource
    private PermissionMapper permissionMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */

    public Permission queryById(Long id) {
        return this.permissionMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param permission 筛选条件
     * @return 查询结果
     */
    public Set<Permission> queryAllByPermission(Permission permission) {
        return permissionMapper.queryAllByLimit(permission);
    }

    /**
     * 新增数据
     *
     * @param permission 实例对象
     * @return 实例对象
     */

    public Permission insert(Permission permission) {
        this.permissionMapper.insert(permission);
        return permission;
    }

    /**
     * 修改数据
     *
     * @param permission 实例对象
     * @return 实例对象
     */

    public Permission update(Permission permission) {
        this.permissionMapper.update(permission);
        return this.queryById(permission.getId());
    }

    /**
     * 获取用户对应的角色Id
     * @param id
     * @return
     */
    public List<Long> getPermissionIdListByRoleId(Long id){
        return permissionMapper.getPermissionIdListByRoleId(id);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */

    public boolean deleteById(Long id) {
        return this.permissionMapper.deleteById(id) > 0;
    }
}
